package jUnitTest;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;

import org.junit.*;

import depot.DimensionFormatException;
import depot.DuplicateIDException;
import depot.IDFormatException;
import depot.NoExistParcelException;
import depot.Parcel;
import depot.ParcelMap;

public class ParcelMapTest {
	
	private ParcelMap parcelMap;
	
	/**
	 * Initialize the parcelMap and set up the record of parcel
	 * @throws DuplicateIDException
	 * @throws IDFormatException
	 * @throws DimensionFormatException
	 */
	@Before
	public void setUp() throws DuplicateIDException, IDFormatException, DimensionFormatException{
		parcelMap = new ParcelMap();
		parcelMap.putParcel(new Parcel("N279",1,3.5,"9x2x3"));

	}
	
	
	/**
	 * After finishing the tests, reset the parcelMap.
	 */
	@After
	public void teardown(){
		parcelMap = new ParcelMap();
	}
	
	
	/**
	 * This method tests if the DuplicateIDException works well
	 * @throws DuplicateIDException
	 * @throws NoExistParcelException
	 * @throws IDFormatException
	 * @throws DimensionFormatException
	 */
	@Test (expected = DuplicateIDException.class)
	public void testPutParcel() throws DuplicateIDException, NoExistParcelException, IDFormatException, DimensionFormatException{
		parcelMap.putParcel(new Parcel("N279",3,5.5,"3x4x5"));
		
		parcelMap.putParcel(new Parcel("N211",3,5.5,"3x4x5"));
	}
	
	/**
	 * This method tests if the NoExistParcelException works well
	 * @throws NoExistParcelException
	 */
	@Test (expected = NoExistParcelException.class)
	public void testFindParcel() throws NoExistParcelException{
		Parcel parcela = parcelMap.findParcel("L202");
		Parcel parcelb = parcelMap.findParcel("L292");
	}
	
	/**
	 * This method tests if the parcel has been removed successfully.
	 */
	@Test
	public void testRemoveParcel(){
		String [] parcelID = {"N279", "L902"};	

		try{		    
			String message1 = "Fail for removing parcel :"+ parcelID[0];
			assertTrue(message1,parcelMap.removeParcel(parcelID[0]));
		}catch(AssertionError ae){
			System.out.print(ae.getMessage());
			}
		
		
		try{		    
			String message2 = "Fail for removing parcel :"+ parcelID[1];
			assertTrue(message2, parcelMap.removeParcel(parcelID[1]));
		}catch(AssertionError ae){
			System.out.print(ae.getMessage());
			}
	}

}
